// import http from '@/utils/util'
// 系统设置
import { commonEditForm, commonQuery, commonVisible, commonOptions, commonRule } from '@/api/config';
export const sysMenuMixin = {
    data() {
        return {
            options: [
                Object.assign({}, commonOptions)
            ],
            ...commonVisible,
            rules: {
                name: [commonRule],
                parentName: [
                    commonRule
                ]
            },
            editForm: {
                id: "",
                pid: "0",
                children: [],
                name: "",
                url: null,
                type: 0,
                icon: "",
                permissions: null,
                sort: 0,
                createDate: null,
                parentName: null,
                options: [
                    Object.assign({}, commonOptions, { children: [] })
                ]
            },
            addForm: {
                id: "",
                pid: "0",
                children: [],
                name: "",
                url: null,
                type: 0,
                icon: "",
                permissions: null,
                sort: 0,
                createDate: null,
                parentName: null,
                options: [
                    Object.assign({}, commonOptions, { children: [] })
                ],
                value: "",
                icons: icons
            },
            form: {
                name: ""
            },
            tableData: [
                {
                    id: "",
                    pid: "",
                    children: [],
                    name: "",
                    url: null,
                    type: 0,
                    icon: "",
                    permissions: null,
                    sort: 0,
                    createDate: null,
                    parentName: null
                }
            ]
        }
    },
    methods: {
        // 获取数据
        getSMData({ order = "", orderField = "", _t = Date.now() }) {
            this.$axios
                .get("/sys/menu/list", {
                    params: {
                        order,
                        orderField,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    function myMap(array) {
                        array.map(item => {
                            item.show = false;
                            if (item.children && item.children.length) {
                                return myMap(item.children);
                            }
                        });
                    }
                    myMap(res.data);

                    function handleType(array) {
                        array.map(item => {
                            item.type = item.type === 0 ? "菜单" : "按钮";
                            if (item.children && item.children.length) {
                                return handleType(item.children);
                            }
                        });
                    }
                    handleType(res.data);
                    this.tableData = res.data;
                })
                .catch(() => { });
        }
    }
}

export const sysParamsMixin = {
    data() {
        return {
            query: {
                paramCode: "",
                pageIndex: 1,
                pageSize: 20
            },
            tableData: [
                {
                    id: "",
                    paramCode: "",
                    paramValue: "",
                    remark: "",
                    createDate: null,
                    updateDate: null
                }
            ],
            multipleSelection: [],
            delList: [],
            ...commonVisible,
            pageTotal: 0,
            rules: {
                paramCode: [
                    commonRule
                ],
                paramValue: [
                    commonRule
                ]
            },
            editForm: Object.assign({}, commonEditForm, {
                paramCode: "",
                paramValue: "",
                updateDate: null
            }),
            addForm: {
                paramCode: "",
                paramValue: "",
                remark: "",
                createDate: null,
                updateDate: null
            },
            idx: -1,
            ids: []
        };
    },
    methods: {
        // 获取数据
        getSysParamsData({
            order = "",
            orderField = "",
            page = this.query.pageIndex,
            limit = this.query.pageSize,
            paramCode = this.query.paramCode,
            _t = Date.now()
        }) {
            this.$axios
                .get("/sys/params/page", {
                    params: {
                        order,
                        orderField,
                        page,
                        limit,
                        paramCode,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    this.pageTotal = res.data.total || 0;
                    this.tableData = res.data.list;
                })
                .catch(() => { });
        }
    }
}

export const sysDictMixin = {
    data() {
        return {
            query: Object.assign({}, commonQuery, {
                pid: "0",
                dictName: "",
                dictType: "",
                dictValue: "",
            }),
            tableData: [
                {
                    id: "",
                    pid: "",
                    dictType: "",
                    dictName: "",
                    dictValue: "",
                    remark: "",
                    sort: "",
                    createDate: null,
                    updateDate: null
                }
            ],
            multipleSelection: [],
            rules: {
                dictName: [
                    commonRule
                ],
                dictType: [
                    commonRule
                ],
                sort: [commonRule]
            },
            addForm: {
                dictName: "",
                dictType: "",
                sort: 0,
                remark: "",
                pid: "0",
                dictValue: ""
            },
            editForm: Object.assign({}, commonEditForm, {
                dictName: "",
                dictType: "",
                sort: 0,
                pid: "0",
                dictValue: "",
                updateDate: ""
            }),
            ...commonVisible,
            pageTotal: 0,

            idx: -1,
            ids: []
        };
    },
    methods: {
        // 获取数据
        getSDData({
            order = this.query.order,
            orderField = this.query.orderField,
            page = this.query.pageIndex,
            limit = this.query.pageSize,
            pid = this.query.pid,
            dictName = this.query.dictName,
            dictType = this.query.dictType,
            dictValue = this.query.dictValue,
            _t = Date.now()
        }) {
            this.$axios
                .get("/sys/dict/page", {
                    params: {
                        order,
                        orderField,
                        page,
                        limit,
                        pid,
                        dictName,
                        dictType,
                        dictValue,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    this.pageTotal = res.data.total || 0;
                    this.tableData = res.data.list;
                })
                .catch(() => { });
        }
    }
}

export const jobScheduleMixin = {
    data() {
        return {
            query: Object.assign({}, commonQuery, {
                beanName: "",
                jobId: ""
            }),
            tableData: [
                {
                    id: "",
                    beanName: "",
                    params: "",
                    cronExpression: "",
                    status: 0,
                    remark: "",
                    createDate: null
                }
            ],
            // 日志列表
            slTableData: [
                {
                    id: "",
                    jobId: "",
                    beanName: "",
                    params: "",
                    status: 0,
                    consumeTime: "",
                    runDate: ""
                }
            ],
            multipleSelection: [],
            delList: [],
            ...commonVisible,
            scheduleLogVisible: false,
            pageTotal: 0,
            rules: {
                beanName: [
                    commonRule
                ],
                cronExpression: [
                    commonRule
                ]
            },
            addForm: {
                beanName: "",
                params: "",
                cronExpression: "",
                status: 0,
                remark: ""
            },
            editForm: Object.assign({}, commonEditForm, {
                beanName: "",
                params: "",
                cronExpression: "",
                status: "",
            }),
            scheduleLogForm: {},
            idx: -1,
            ids: [],
            dddown: true // 防止重复点击
        };
    },
    methods: {
        // 获取数据
        getJSData({
            order = this.query.order,
            orderField = this.query.orderField,
            page = this.query.pageIndex,
            limit = this.query.pageSize,
            beanName = this.query.beanName,
            _t = Date.now()
        }) {
            this.$axios
                .get("/sys/schedule/page", {
                    params: {
                        order,
                        orderField,
                        page,
                        limit,
                        beanName,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    // console.log(res);
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    this.pageTotal = res.data.total || 0;
                    this.tableData = res.data.list;
                    this.tableData.map(item => {
                        item.status = item.status === 0 ? "暂停" : "正常";
                    });
                })
                .catch(() => { });
        }
    }
}

export const ossOssMixin = {
    data() {
        return {
            query: Object.assign({}, commonQuery),
            tableData: [
                {
                    id: "",
                    creator: null,
                    createDate: "",
                    updater: null,
                    updateDate: "",
                    url: ""
                }
            ],
            multipleSelection: [],
            delList: [],
            uploadFileVisable: false,
            cloudVisable: false,
            pageTotal: 0,
            rules: {
                qiniuDomain: [
                    commonRule
                ],
                qiniuAccessKey: [
                    commonRule
                ],
                qiniuSecretKey: [
                    commonRule
                ],
                qiniuBucketName: [
                    commonRule
                ],
                aliyunDomain: [
                    commonRule
                ],
                aliyunEndPoint: [
                    commonRule
                ],
                aliyunAccessKeyId: [
                    commonRule
                ],
                aliyunAccessKeySecret: [
                    commonRule
                ],
                aliyunBucketName: [
                    commonRule
                ],
                qcloudDomain: [
                    commonRule
                ],
                qcloudAppId: [
                    commonRule
                ],
                qcloudSecretId: [
                    commonRule
                ],
                qcloudSecretKey: [
                    commonRule
                ],
                qcloudBucketName: [
                    commonRule
                ],
                qcloudRegion: [
                    commonRule
                ],
                fastdfsDomain: [
                    commonRule
                ],
                localDomain: [
                    commonRule
                ],
                localPath: [
                    commonRule
                ]
            },
            uploadFileForm: {},
            cloudForm: {
                inputVisable: 1,
                type: 1,
                qiniuDomain: "",
                qiniuPrefix: "",
                qiniuAccessKey: "",
                qiniuSecretKey: "",
                qiniuBucketName: "",
                aliyunDomain: "",
                aliyunPrefix: "",
                aliyunEndPoint: "",
                aliyunAccessKeyId: "",
                aliyunAccessKeySecret: "",
                aliyunBucketName: "",
                qcloudDomain: "",
                qcloudPrefix: "",
                qcloudAppId: null,
                qcloudSecretId: "",
                qcloudSecretKey: "",
                qcloudBucketName: "",
                qcloudRegion: null,
                fastdfsDomain: null,
                localDomain: null,
                localPrefix: null,
                localPath: null,
                options: [
                    {
                        value: "选项1",
                        label: "北京一区(华北)"
                    },
                    {
                        value: "选项2",
                        label: "北京"
                    },
                    {
                        value: "选项3",
                        label: "上海(华东)"
                    },
                    {
                        value: "选项4",
                        label: "广州(华南)"
                    },
                    {
                        value: "选项5",
                        label: "成都(西南)"
                    },
                    {
                        value: "选项6",
                        label: "重庆"
                    },
                    {
                        value: "选项7",
                        label: "新加波"
                    },
                    {
                        value: "选项8",
                        label: "香港"
                    },
                    {
                        value: "选项9",
                        label: "多伦多"
                    },
                    {
                        value: "选项10",
                        label: "法兰克福"
                    }
                ],
                value: ""
            },
            idx: -1,
            ids: [],
            token: "",
            url: this.getToken(document.cookie)
        };
    },
    methods: {
        // 获取数据
        getOOData({
            order = this.query.order,
            orderField = this.query.orderField,
            page = this.query.pageIndex,
            limit = this.query.pageSize,
            _t = Date.now()
        }) {
            this.$axios
                .get("/sys/oss/page", {
                    params: {
                        order,
                        orderField,
                        page,
                        limit,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    this.pageTotal = res.data.total || 0;
                    this.tableData = res.data.list;
                })
                .catch(() => { });
        }
    }
}
